﻿using System.Linq;

namespace YouTubeDownloadExtension
{
    public static class VideoFormatExtensions
    {
        private const string DefaultFileExtension = "unknown";

        public static string ToFileExtension(this VideoFormat format)
        {
            var fieldInfo = typeof(VideoFormat).GetField(format.ToString());
            var attributes = fieldInfo.GetCustomAttributes(typeof(FileExtensionAttribute), false) as FileExtensionAttribute[];

            return attributes != null && attributes.Length > 0 ? attributes.First().Suffix : DefaultFileExtension;
        }
    }
}
